from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.edge.service import Service as EdgeService
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.action_chains import ActionChains
from actions import *
import time

def main():
    # 设置浏览器驱动路径
    edge_driver_path = "/home/huangxin/webdriver/msedgedriver"

    # 创建 Edge 服务对象
    edge_service = EdgeService(executable_path=edge_driver_path)

    # 创建 Edge 浏览器对象，传递服务对象
    driver = webdriver.Edge(service=edge_service)

    # 打开登录页面
    driver.get(LOGIN_URL)

    # 执行登录操作
    login(driver, USER_NAME, PASSWORD)

    time.sleep(3)

    cookies = driver.get_cookies()
    print(cookies)
    # 交易
    get_market_list(driver)
    time.sleep(10)

    cookies = driver.get_cookies()
    print(cookies)
    # 我的订单
    # navigate_to_my_orders(driver)
    # time.sleep(3)

    # 我的发布
    navigate_to_my_posts(driver)
    time.sleep(10)
    # while True:
    #     # 确认订单是否已撤销
    #     if has_order_data(driver):
    #         revoke_publication(driver)
    #         print("订单已成功撤销")
    #         time.sleep(1)  # 等待一段时间以确保订单发布
    #     else:
    #         back_to(driver)
    #         break

    # print("订单撤销完成 现在进入发布订单")
    # time.sleep(2)

    # 发布新订单
    for _ in range(5):
        navigate_to_post(driver)
        # time.sleep(2)
        # begin_sale_5(driver)

        # navigate_to_post(driver)
        time.sleep(10)  # 等待一段时间以确保订单发布
        begin_sale_10(driver)
        time.sleep(10)
    time.sleep(3)
    # while True:
    #     navigate_to_my_purchases(driver)
    #     time.sleep(5)
    #     if has_order_data(driver):
    #         print("我的买入有订单")
    #     else:
    #         print("我的买入无订单")

    #     navigate_to_my_sales(driver)
    #     time.sleep(5)
    #     if has_order_data(driver):
    #         print("我的出售有订单")
    #     else:
    #         print("我的出售无订单")

    time.sleep(30)
    # 其他功能实现...

    # 关闭浏览器
    # driver.quit()


if __name__ == "__main__":
    main()
